package com.qiezi.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;

public class VideoBean implements Parcelable {
//    public static String URL = "http://140.82.56.226";
    public static String URL = SiteBean.URL;

    private int id;
    private String image;
    private String name;
    private int weigh;
    private String video_len;
    @JSONField(name = "switch")
    private int switch_;
    private long createtime;
    private long updatetime;
    private String content;
    private String typedata;
    private int category_id;
    private String info;
    private int del;
    private String typedata_text;
    private Date updataDate;
    private String updataString;
    private Date createDate;
    private String createString;
    private DataType dataType;
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");

    public VideoBean(){

    }

    protected VideoBean(Parcel in) {
        id = in.readInt();
        image = in.readString();
        name = in.readString();
        weigh = in.readInt();
        video_len = in.readString();
        switch_ = in.readInt();
        createtime = in.readLong();
        updatetime = in.readLong();
        content = in.readString();
        typedata = in.readString();
        category_id = in.readInt();
        info = in.readString();
        del = in.readInt();
        typedata_text = in.readString();
        updataString = in.readString();
        createString = in.readString();
    }

    public static final Creator<VideoBean> CREATOR = new Creator<VideoBean>() {
        @Override
        public VideoBean createFromParcel(Parcel in) {
            return new VideoBean(in);
        }

        @Override
        public VideoBean[] newArray(int size) {
            return new VideoBean[size];
        }
    };

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getImage() {
        return URL + image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWeigh() {
        return weigh;
    }

    public void setWeigh(int weigh) {
        this.weigh = weigh;
    }

    public String getVideo_len() {
        return video_len;
    }

    public void setVideo_len(String video_len) {
        this.video_len = video_len;
    }

    public int getSwitch_() {
        return switch_;
    }

    public void setSwitch_(int switch_) {
        this.switch_ = switch_;
    }

    public String getCreatetime() {
        return createString;
    }

    public void setCreatetime(long createtime) {
        this.createtime = createtime;
        createDate = new Date(createtime);
        createString = sdf.format(createDate);
    }

    public String getUpdatetime() {
        return updataString;
    }

    public void setUpdatetime(long updatetime) {
        this.updatetime = updatetime;
        updataDate = new Date(updatetime);
        updataString = sdf.format(updataDate);
    }

    public String getContent() {
        return URL+content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public DataType getTypedata() {

        return dataType;
    }

    public void setTypedata(String typedata) {
        this.typedata = typedata;
        try {
            dataType = DataType.valueOf(typedata);
        }catch (Exception e){
            dataType = DataType.empty;
        }
    }

    public int getCategory_id() {
        return category_id;
    }

    public void setCategory_id(int category_id) {
        this.category_id = category_id;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public int getDel() {
        return del;
    }

    public void setDel(int del) {
        this.del = del;
    }

    public String getTypedata_text() {
        return typedata_text;
    }

    public void setTypedata_text(String typedata_text) {
        this.typedata_text = typedata_text;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\n{\n\tid:")
                .append(getId())
                .append("\n\timage:").append(getImage())
                .append("\n\tname:").append(getName())
                .append("\n\tweigh:").append(getWeigh())
                .append("\n\tvideo_len:").append(getVideo_len())
                .append("\n\tswitch:").append(getSwitch_())
                .append("\n\tcreatetime:").append(getCreatetime())
                .append("\n\tupdatetime:").append(getUpdatetime())
                .append("\n\tcontent:").append(getContent())
                .append("\n\ttypedata:").append(getTypedata())
                .append("\n\tcategory_id:").append(getCategory_id())
                .append("\n\tinfo:").append(getInfo())
                .append("\n\tdel:").append(getDel())
                .append("\n\ttypedata_text:").append(getTypedata_text())
                .append("\n}");

        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (!(obj instanceof VideoBean)) return false;
        VideoBean v = (VideoBean) obj;
        return v.getId() == getId();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeInt(id);
        dest.writeString(image);
        dest.writeString(name);
        dest.writeInt(weigh);
        dest.writeString(video_len);
        dest.writeInt(switch_);
        dest.writeLong(createtime);
        dest.writeLong(updatetime);
        dest.writeString(content);
        dest.writeString(typedata);
        dest.writeInt(category_id);
        dest.writeString(info);
        dest.writeInt(del);
        dest.writeString(typedata_text);
        dest.writeString(updataString);
        dest.writeString(createString);
    }
}
